﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace bdnt_pets_system.MyUserControls
{
    public class MyTextBox : TextBox
    {
        public MyTextBox()
        {
            this.MinWidth = 120;
            this.Height = 28;
            this.GotFocus += new RoutedEventHandler(tb_GotFocus);
            this.LostFocus += new RoutedEventHandler(tb_LostFocus);
        }

        void tb_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {

                var cuObj = (sender as TextBox);
                if (cuObj.Text == cuObj.Tag.ToString() || string.IsNullOrEmpty(cuObj.Text))
                {
                    cuObj.Text = cuObj.Tag.ToString();
                    cuObj.Foreground = new SolidColorBrush(Colors.Gray);
                }
                else
                    cuObj.Foreground = new SolidColorBrush(Colors.Black);
            }
            catch
            {

            }
        }

        void tb_GotFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                var cuObj = (sender as TextBox);
                if (cuObj.Text == cuObj.Tag.ToString())
                {
                    cuObj.Foreground = new SolidColorBrush(Colors.Gray);
                    cuObj.Text = "";
                }
                else
                    cuObj.Foreground = new SolidColorBrush(Colors.Black);
            }
            catch
            {

            }
        }
    }
}
